package com.example.demo.log;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author: yby
 * @desc:
 * @date: 2024/9/4 10:56
 */
public class JsonLog {

    private static ObjectMapper mapper = null;

    static {
        mapper = new ObjectMapper();
//        mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
//        mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
    }

    public static String toJson(Object o) {
        try {

            ObjectMapper mapper = new ObjectMapper();
            return mapper.writeValueAsString(o);
        } catch (Exception e) {
            return "";
        }
    }
}
